/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.bean.util;

import com.openbravo.format.Formats;
import com.openbravo.bean.BusinessPartner;
import com.openbravo.bean.infobean.CustomerInfo;
import com.openbravo.pos.util.RoundUtils;
import com.openbravo.pos.util.StringUtils;
import java.util.Date;

/**
 *
 * @author Administrator
 */
public class CustomerHelper {

    public static String printCurDebt(BusinessPartner c) {
        return Formats.CURRENCY.formatValue(RoundUtils.getValue(c.getCurdebt()));
    }

   public static String printMaxDebt(BusinessPartner c) {
        return Formats.CURRENCY.formatValue(RoundUtils.getValue(c.getMaxdebt()));
    }

   public static void updateCurDebt(BusinessPartner c,Double amount, Date d) {

        c.curdebt = c.curdebt == null ? amount : c.curdebt + amount;

        if (RoundUtils.compare(c.curdebt, 0.0) > 0) {
            if (c.curdate == null) {
                // new date
                c.curdate = d;
            }
        } else if (RoundUtils.compare(c.curdebt, 0.0) == 0) {
            c.curdebt = null;
            c.curdate = null;
        } else { // < 0
            c.curdate = null;
        }
    }

    public static String printTaxid(CustomerInfo c) {
        return StringUtils.encodeXML(c.getTaxid());
    }

    public static String printName(CustomerInfo c) {
        return StringUtils.encodeXML(c.getName());
    }
}
